package cn.net.xyan.yypt

import org.junit.Test
import cn.linkingcloud.openapi.LopClient
import cn.net.xyan.blossom.kotlin.*
import cn.net.xyan.yypt.utils.ResourceUtils.Companion.readResource
import cn.net.xyan.yypt.dto.CreatePolymerizationQRCodeReq
import cn.net.xyan.yypt.dto.LinkingCloudResponse
import cn.net.xyan.yypt.dto.QRCodeRsp
import java.math.BigDecimal
import java.text.SimpleDateFormat


class LKTest{

    companion object {
        const val AppID = "LCOP20171228012536079"
        const val OpenURL = "http://openapi.linkingcloud.cn:8816/gateway"

       // const val BaseURL = "http://yypt.xyan.net.cn:18002/ydpt/public/qrCode?value="

        const val BaseURL = "http://192.168.203.60:8080/ydpt/public/qrCode?value="

        var charset = "utf-8"
        var sign_type = "rsa"


    }

    @Test
    fun test1(){
        val df = SimpleDateFormat("yyyyMMddHHmmssSSS")

        val private_key = readResource("key/app_private.key")
        val public_key = readResource("key/open_public.key")

        val client = LopClient(OpenURL, AppID, private_key, charset, public_key, sign_type)

        var req = CreatePolymerizationQRCodeReq()

       // var req = CreateQRCodeOrderReq()

        req.outTradeNo = df.format(DateExt.now)

        req.totalAmount = BigDecimal("10")

        req.subject = "测试订单"

        req.body = "3"

        req.operatorID = "1"

        req.terminalID = "2"

        req.disablePayChannels = "credit_group"

        req.timeoutExpress = "90m"

     //   req.paymentType = "alipay"

        req.notifyURL = "http://yypt.xyan.net.cn:18002/ydpt/public/callback"

        val json = req.json

        println(json)

        val rsp = client.InvokeMethod("lc.trade.polymerization.pay",json)
       // val rsp = client.InvokeMethod("lc.trade.qrcode.pay",json)

        println(rsp)

        val rspObj: LinkingCloudResponse<QRCodeRsp>? = rsp.json2obj(LinkingCloudResponse::class.parametricType(QRCodeRsp::class.javaType))


        println(rspObj?.json)

        println("$BaseURL${rspObj?.bizContent?.qrCode}")
    }
}